﻿using System;

using SeriesManager.View;
using SeriesManager.ViewModel;
using WinRTFramework.FrameworkConfiguration;

namespace SeriesManager.Framework
{
    class ViewViewModelMapper : IViewViewModelMapper
    {
        private IIoCAdapter _ioCAdapter;

        public ViewViewModelMapper(IIoCAdapter ioCAdapter)
        {
            _ioCAdapter = ioCAdapter;
        }

        public Type GetViewTypeForViewModelType(Type viewModelType, object navigationParameter)
        {
            if (viewModelType == typeof(SplashViewModel))
                return typeof(SplashView);

            if (viewModelType == typeof(ActorViewModel))
                return typeof (ActorView);

            if (viewModelType == typeof(AirViewModel))
                return typeof(AirView);

            if (viewModelType == typeof(EpisodeViewModel))
                return typeof(EpisodeView);

            if (viewModelType == typeof(MediaDetailViewModel))
                return typeof(MediaDetailView);

            if (viewModelType == typeof(MediaViewModel))
                return typeof(MediaView);

            if (viewModelType == typeof(SearchViewModel))
                return typeof(SearchView);

            if (viewModelType == typeof(SeasonViewModel))
                return typeof(SeasonView);

            if (viewModelType == typeof(SeriesViewModel))
                return typeof(SeriesView);

            if (viewModelType == typeof(SubscriptionViewModel))
                return typeof(SubscriptionView);

            if (viewModelType == typeof(SettingsViewModel))
                return typeof(SettingsView);

            throw new ArgumentOutOfRangeException("viewModelType");
        }

        public object GetViewModelForView(Type viewType, object navigationParameter)
        {
            if (viewType == typeof(SplashView))
                return _ioCAdapter.GetInstanceOfType(typeof(SplashViewModel));

            if (viewType == typeof(ActorView))
                return _ioCAdapter.GetInstanceOfType(typeof(ActorViewModel));

            if (viewType == typeof(AirView))
                return _ioCAdapter.GetInstanceOfType(typeof(AirViewModel));

            if (viewType == typeof(EpisodeView))
                return _ioCAdapter.GetInstanceOfType(typeof(EpisodeViewModel));

            if (viewType == typeof(MediaDetailView))
                return _ioCAdapter.GetInstanceOfType(typeof(MediaDetailViewModel));

            if (viewType == typeof(MediaView))
                return _ioCAdapter.GetInstanceOfType(typeof(MediaViewModel));

            if (viewType == typeof(SearchView))
                return _ioCAdapter.GetInstanceOfType(typeof(SearchViewModel));

            if (viewType == typeof(SeasonView))
                return _ioCAdapter.GetInstanceOfType(typeof(SeasonViewModel));

            if (viewType == typeof(SeriesView))
                return _ioCAdapter.GetInstanceOfType(typeof(SeriesViewModel));

            if (viewType == typeof(SubscriptionView))
                return _ioCAdapter.GetInstanceOfType(typeof(SubscriptionViewModel));

            if (viewType == typeof(SettingsView))
                return _ioCAdapter.GetInstanceOfType(typeof(SettingsViewModel));

            throw new ArgumentOutOfRangeException("viewType");
        }
    }
}
